package org.tmsps.ne4spring.sql;

import org.tmsps.ne4spring.utils.ChkTools;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SqlInUtil {

	public static String getInParams(String[] params) {
		StringBuilder sb = new StringBuilder();
		for (String param : params) {
			if (ChkTools.isNull(param)) {
				continue;
			}
			sb.append("'").append(param).append("',");
		}
		if (sb.length() > 0) {
			sb.deleteCharAt(sb.length() - 1);
		}
		return sb.toString();
	}

	public static String getInParams(Set<String> params) {
		StringBuilder sb = new StringBuilder();
		for (String param : params) {
			sb.append("'").append(param).append("',");
		}
		if (sb.length() > 0) {
			sb.deleteCharAt(sb.length() - 1);
		}
		return sb.toString();
	}

	public static String getInParams(List<String> params) {
		StringBuilder sb = new StringBuilder();
		for (String param : params) {
			sb.append("'").append(param).append("',");
		}
		if (sb.length() > 0) {
			sb.deleteCharAt(sb.length() - 1);
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		Set<String> params = new HashSet<>();
		params.add("1");
		params.add("11");
		params.add("33");
		params.add("43");
		System.err.println(getInParams(params));
	}

}
